//
//  RecStoreListCell.swift
//

import UIKit

class RecStoreListCell: UICollectionViewCell {
    
    private lazy var iconView: UIImageView = {
        let view = UIImageView()
        view.corner(radii: 8.fit)
        view.contentMode = .scaleToFill
        return view
    }()
    
    private lazy var bottomBgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.black.alpha(0.3)
        return view
    }()
    
    private lazy var countLabel: UILabel = {
        let view = UILabel()
        view.textColor = UIColor.white
        view.font = 10.font
        return view
    }()
    
    private lazy var titleLabel: UILabel = {
        let view = UILabel()
        view.textColor = UIColor.black
        view.font = 15.font
        return view
    }()
    
    private lazy var detailLabel: UILabel = {
        let view = UILabel()
        view.textColor = UIColor.gray
        view.font = 13.font
        view.numberOfLines = 2
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
           
        addSubviews()
    }
       
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addSubviews() {
        backgroundColor = .sysTableView
        contentView.addSubview(iconView)
        iconView.addSubview(bottomBgView)
        bottomBgView.addSubview(countLabel)
        contentView.addSubview(titleLabel)
        contentView.addSubview(detailLabel)
        
        iconView.snp.makeConstraints { (make) in
            make.left.top.bottom.equalToSuperview()
            make.height.equalTo(iconView.snp.width)
        }
        
        bottomBgView.snp.makeConstraints { (make) in
            make.bottom.left.right.equalToSuperview()
            make.height.equalTo(20.fit)
        }
        
        countLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10.fit)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(8.fit)
            make.left.equalTo(iconView.snp.right).offset(6.fit)
            make.right.equalToSuperview().offset(-10.fit)
        }
        
        detailLabel.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(8.fit)
            make.left.equalTo(iconView.snp.right).offset(6.fit)
            make.right.equalToSuperview().offset(-10.fit)
        }
    }
    
    func update(_ model: RecChildDataItemsModel) {
        iconView.kf_set(model.storeDetail.thumbs.medium_thumb)
        countLabel.text = "共\(model.storeDetail.program_count)集"
        titleLabel.text = model.storeDetail.title
        detailLabel.text = model.storeDetail.description
    }
    
    func update(list model: RecChildDataItemsModel) {
        iconView.kf_set(model.thumbs.medium_thumb)
        countLabel.text = "共\(model.program_count)集"
        titleLabel.text = model.title
        detailLabel.text = model.description
    }
}
